/**
 * 
 */
package com.yidu.menuProject.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.yidu.menuProject.action.vo.MealVo;
import com.yidu.menuProject.common.Pages;
import com.yidu.menuProject.commont.Tools;
import com.yidu.menuProject.dao.EhyManagerModelMapper;
import com.yidu.menuProject.dao.EhyManagerRoleModelMapper;
import com.yidu.menuProject.dao.FoodModelMapper;
import com.yidu.menuProject.dao.MealModelMapper;
import com.yidu.menuProject.dao.MealtypeModelMapper;
import com.yidu.menuProject.dao.TuserModelMapper;
import com.yidu.menuProject.model.EhyManagerModel;
import com.yidu.menuProject.model.EhyManagerRoleModel;
import com.yidu.menuProject.model.MealModel;
import com.yidu.menuProject.model.MealtypeModel;
import com.yidu.menuProject.model.TuserModel;

/**
 * @author Bruce
 * @date 2018年6月9日
 * @version 1.0
 */
@Service
public class MealServiceImp implements MealService{
	@Resource
	private MealModelMapper MealDao;
	@Resource
	private TuserModelMapper TuserModelDao;
	@Resource
	private MealtypeModelMapper mealtypeModelMapper;
	@Resource
	private FoodModelMapper foodModelDao;
	@Resource
	private EhyManagerRoleModelMapper ehyManagerRoleModelMapper;
	@Resource
	private EhyManagerModelMapper ehyManagerModelMapper;
	/**
	 * 删除
	 */
	@Override
	public int deleteByPrimaryKey(MealVo vo) {
		return MealDao.deleteByPrimaryKey(vo);
		
	}
	/**
	 * 增加
	 */
	@Override
	public int insert(MealVo vo) {
		MealModel po = new MealModel();
		BeanUtils.copyProperties(vo, po);
		return MealDao.insert(vo);
	}

	@Override
	public int insertSelective(MealVo vo) {
		return MealDao.insertSelective(vo);
	}

	@Override
	public MealModel selectByPrimaryKey(String mealId) {
		return MealDao.selectByPrimaryKey(mealId);
	}

	/**
	 * 修改
	 */
	@Override
	public int updateByPrimaryKeySelective(MealVo vo) {
		return MealDao.updateByPrimaryKeySelective(vo);
	}

	@Override
	public int updateByPrimaryKey(MealModel record) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	
	
	/**
	 * 查询所有
	 */
	@Override
	public List<MealModel> selectFindAll(String da) {
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("mealTypeid",da);
		 List<MealModel> list= MealDao.selectFindAll(map);
		return list;
	}
	
	/**
	 * 搜索框查询所有
	 */
	@Override
	public List<MealModel> selectFindAllVague(String mealName) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("mealName",mealName);
	 List<MealModel> list= MealDao.selectFindAllVague(map);
	return list;
	}
	/**
	 * 用户注册
	 */
	@Override
	public int insertSelectiveUser(TuserModel tuserModel) {
		tuserModel.setUserId(Tools.getRandomString(16));
		return TuserModelDao.insertSelective(tuserModel);
	}
	/**
	 * 用户登录
	 */
	@Override
	public TuserModel loginUser(TuserModel tuserModel) {
		
		return TuserModelDao.loginUser(tuserModel);
	}
	
	/**
     * 查询所有商店类型
     * @return
     */
	@Override
	public List<MealtypeModel> findAllType(){
    	return mealtypeModelMapper.findAllType();
    }
	/**
	 * 查询所有
	 */
	@Override
	public List<MealModel> selectAll(Pages page){
		return MealDao.selectAll(page);
	}
	/**
	 * 行数
	 */
	@Override
	public int selectCount(Pages page) {
		return MealDao.selectCount(page);
	}
	
	@Override
	public int delete(MealVo vo) {
		int rows = MealDao.deleteByPrimaryKey(vo);
		System.out.println(vo.getMealId()+"===========ggg");
		foodModelDao.delete(vo.getMealId());
		return rows;
	}
	
	/**
	 * 审核
	 */
	@Override
	public int updateVet(MealVo vo) {
		//先查询出商店对应的商家账号
		EhyManagerModel ehyManagerModel =  ehyManagerModelMapper.findMealHWT(vo.getMealId());
		
		EhyManagerRoleModel emrm = new EhyManagerRoleModel();
		emrm.setManId(ehyManagerModel.getManId());
		emrm.setMrId(Tools.getRandomString(16));
		emrm.setRoleId("5");
		//增加角色人员连接表
		ehyManagerRoleModelMapper.insertSelective(emrm);
		return MealDao.updateByPrimaryKeySelective(vo);
	}
	
	/**
	 * 审核查询所有
	 */
	@Override
	public List<MealModel> select(Pages page) {
		return MealDao.select(page);
	}
	@Override
	public int selectCounts(Pages page) {
		return MealDao.selectCounts(page);
	}

	
}
